package cn.lopr.im.android.db.helper;

import android.app.Application;

import cn.lopr.im.android.db.entity.HomeDialogue;
import cn.lopr.im.android.db.entity.Message;
import cn.lopr.im.android.db.gen.HomeDialogueDao;
import cn.lopr.im.android.db.gen.MessageDao;

/**
 * 初始化、存放及获取DaoUtils
 */
public class DaoUtilsStore {
    private volatile static DaoUtilsStore instance = null;
    private final CommonDaoUtils<Message> mMessageDaoUtils;
    private final CommonDaoUtils<HomeDialogue> mHomeDialogueUtils;


    public static void init(Application mApplication) {
        if (instance == null) {
            instance = new DaoUtilsStore(mApplication);
        }
    }

    public static DaoUtilsStore getInstance() {
        //if (instance == null) {
        //getInstance(mApplication);
        //}
        return instance;
    }

    private DaoUtilsStore(Application mApplication) {
        DaoManager mManager = DaoManager.getInstance(mApplication);
        MessageDao _MessageDao = mManager.getDaoSession().getMessageDao();
        HomeDialogueDao _HomeDialogueDao = mManager.getDaoSession().getHomeDialogueDao();
        this.mMessageDaoUtils = new CommonDaoUtils<>(Message.class, _MessageDao);
        this.mHomeDialogueUtils = new CommonDaoUtils<>(HomeDialogue.class, _HomeDialogueDao);
    }

    public CommonDaoUtils<Message> getMessageDaoUtils() {
        return mMessageDaoUtils;
    }

    public CommonDaoUtils<HomeDialogue> getHomeDialogueUtils() {
        return mHomeDialogueUtils;
    }
}


